def is_valid_sequence(sequence):
    stack = []
    brackets = {"(": ")", "[": "]", "<": ">", "{": "}"}

    for char in sequence:
        if char in brackets.keys():
            stack.append(char)
        elif char in brackets.values():
            if not stack or brackets[stack.pop()] != char:
                return False
    
    return not stack  
sequence = input("Введите скобочную последовательность: ")
print(is_valid_sequence(sequence))
